import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueDevTools from 'vite-plugin-vue-devtools'

// https://vite.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    vueDevTools(),
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    },
  },
  server: {
    host: '0.0.0.0', // 允许局域网访问
    port: 3000, // 指定端口
    open: true, // 自动打开浏览器
    cors: true, // 启用CORS
    proxy: {
      '/profile': {
        target: 'http://192.168.77.14:8080',
        changeOrigin: true,
        secure: false,
        rewrite: (path) => path.replace(/^\/profile/, '/profile')
      }
    }
  },
  preview: {
    host: '0.0.0.0', // 预览模式也允许局域网访问
    port: 4173,
  }
})
